//个人填报记录

const app = getApp();
var util = require('../../utils/util.js');
var date = util.formatDate(new Date()),allperson;


Page({ 
  data: {
    items: [
      { name: 'all', value: '所有人员' },     
    ],
    date: date,
    list_zyh:true,
    list_mzh:true,
    list_stationh:true,
    diaglogt: true,
    ruler:true,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    // imgalist: ['https://7a6d-zmyy-78bd28-1258642890.tcb.qcloud.la/txl.jpg?sign=bccefd9f27cecdde8f3d7e5fff5eae6e&t=1551966525']
  },
  onLoad: function () {
    this.findOpenid();
    
    if (!wx.cloud) {
      wx.redirectTo({
        url: '../chooseLib/chooseLib',
      })
      return
    }
  },
  checkboxChange :function(e){
    // console.log('发送选择改变，携带值为', e.detail.value[0])
    allperson = e.detail.value[0]
    if (allperson=="all"){
      this.find_data_mz_all();
      this.find_data_zy_all();
      this.find_data_station_all();
    }else{
      this.find_data_mz();
      this.find_data_zy();
      this.find_data_station();
    }
  },
  bindDateChange: function (e) {
   
    this.setData({
      date: e.detail.value
    })
    date = e.detail.value
    if (allperson == "all") {
      this.find_data_mz_all();
      this.find_data_zy_all();
      this.find_data_station_all();
    } else {
      this.find_data_mz();
      this.find_data_zy();
      this.find_data_station();
    }
  },
  findOpenid: function () {
    const db = wx.cloud.database();
   let that =this;
    wx.cloud.callFunction({
      name: 'login',
      complete: res => {
        app.globalData.openid = res.result.openid   
        this.find_data_mz();
        this.find_data_zy();
        this.find_data_station();
////////////////////////////////
        db.collection('glry').where({
          _openid: app.globalData.openid,          
        })
          .get()
          .then(res => {
            // console.log('查询权限res.data', res.data[0].ruler)
            if (res.data[0].ruler) {
              // console.log('有权限')
            that.setData ({
              ruler: false,
            })
            }
            else {
              // console.log('没有权限')
              wx.showToast({
                title: '没有权限',
                icon: 'success',
                // duration: 2000
              })
            }
          })
        //////////////////
      }
    })

  },
  test: function () {
  
    const db = wx.cloud.database();
    //返回数据记录总数
    wx.cloud.callFunction({
      name: 'record_count',
      data: {
        _openid: "oL22f4qviFt-rMECN4sH59EW-q4s",
        // form: "住院分诊台",
        // gzry_addtime: date
      },
      complete: res => {
        this.setData({
          // list_mz: res.result.data,
          data_count_mz: res.result.total
        })
      }
    })
    //返回数据记录前50条
    wx.cloud.callFunction({
      name: 'record_f100',
      data: {
        _openid: "oL22f4qviFt-rMECN4sH59EW-q4s",
        // form: "住院分诊台",
        // gzry_addtime: date
      },
      complete: res => {
        this.setData({
          list_mz: res.result.data,
        })
      }
    })
   




  },
  find_data_station: function () {
    const db = wx.cloud.database();

    //返回数据记录总数
    wx.cloud.callFunction({
      name: 'record_count',
      data: {
        _openid: app.globalData.openid,
        form: "火车站测温台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          // list_mz: res.result.data,
          data_count_station: res.result.total
        })
      }
    })
    //返回数据记录前50条
    wx.cloud.callFunction({
      name: 'record_f100',
      data: {
        _openid: app.globalData.openid,
        form: "火车站测温台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          list_station: res.result.data,
        })
      }
    })




  },
  find_data_mz: function () {
    const db = wx.cloud.database();
  
    //返回数据记录总数
    wx.cloud.callFunction({
      name: 'record_count',
      data: {
        _openid: app.globalData.openid,
        form: "门诊分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          // list_mz: res.result.data,
          data_count_mz: res.result.total
        })
      }
    })
    //返回数据记录前50条
    wx.cloud.callFunction({
      name: 'record_f100',
      data: {
        _openid: app.globalData.openid,
        form: "门诊分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          list_mz: res.result.data,
        })
      }
    })
      
   


  },
  find_data_zy: function () {
    const db = wx.cloud.database();
    //返回数据记录总数
    wx.cloud.callFunction({
      name: 'record_count',
      data: {
        _openid: app.globalData.openid,
        form: "住院分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          // list_mz: res.result.data,
          data_count_zy: res.result.total
        })
      }
    })
    //返回数据记录前50条
    wx.cloud.callFunction({
      name: 'record_f100',
      data: {
        _openid: app.globalData.openid,
        form: "住院分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          list_zy: res.result.data,
        })
      }
    })


  },
  find_data_station_all: function () {
    const db = wx.cloud.database();

    //返回数据记录总数
    wx.cloud.callFunction({
      name: 'record_count',
      data: {
        // _openid: app.globalData.openid,
        form: "火车站测温台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          // list_mz: res.result.data,
          data_count_station: res.result.total
        })
      }
    })
    //返回数据记录前50条
    wx.cloud.callFunction({
      name: 'record_f100',
      data: {
        // _openid: app.globalData.openid,
        form: "火车站测温台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          list_station: res.result.data,
        })
      }
    })
  },
  find_data_mz_all: function () {
    const db = wx.cloud.database();

    //返回数据记录总数
    wx.cloud.callFunction({
      name: 'record_count',
      data: {
        // _openid: app.globalData.openid,
        form: "门诊分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          // list_mz: res.result.data,
          data_count_mz: res.result.total
        })
      }
    })
    //返回数据记录前50条
    wx.cloud.callFunction({
      name: 'record_f100',
      data: {
        // _openid: app.globalData.openid,
        form: "门诊分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          list_mz: res.result.data,
        })
      }
    })
  },
  find_data_zy_all: function () {
    const db = wx.cloud.database();
    //返回数据记录总数
    wx.cloud.callFunction({
      name: 'record_count',
      data: {
        // _openid: app.globalData.openid,
        form: "住院分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          // list_mz: res.result.data,
          data_count_zy: res.result.total
        })
      }
    })
    //返回数据记录前50条
    wx.cloud.callFunction({
      name: 'record_f100',
      data: {
        // _openid: app.globalData.openid,
        form: "住院分诊台",
        gzry_addtime: date
      },
      complete: res => {
        this.setData({
          list_zy: res.result.data,
        })
      }
    })

  },
  
 
  diag_mz: function () {
    this.setData({
      list_mzh: false,
      list_zyh: true,
      list_stationh:true,
      select_fz:"门诊分诊台(最后50条)",
      fzH: false,
    })

  },
 
  diag_zy: function () {
    this.setData({
      list_mzh: true,
      list_zyh: false,
      list_stationh: true,
      select_fz: "住院分诊台(最后50条)",
      fzH:false
    })
  },
  diag_station: function () {
    this.setData({
      list_mzh: true,
      list_zyh: true,
      list_stationh: false,
      select_fz: "车站测温台(最后50条)",
      fzH: false
    })
  },

	/** 
	 * 预览图片
	 */
  previewImage: function (e) {
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: this.data.imgalist // 需要预览的图片http链接列表
    })
  }


})
